
use serde::{Deserialize, Serialize};

use super::Value;

#[derive(Clone, Serialize, Deserialize, Debug)]
pub enum BlackboardValue {
    Value(super::Value),
    Blackboard(String, Value),
    Constant(String, Value),//常量
    Custom(String, Value), //策划表配置变量
}

#[allow(dead_code)]
impl BlackboardValue {
    pub fn get_type_color(&self) -> [u8;4] {
        match self {
            Self::Value(value) => value.value_color(),
            Self::Blackboard(_, value) => value.value_color(),
            Self::Constant(_, value) => value.value_color(),
            Self::Custom(_, value) => value.value_color(),
        }
    }

    pub fn gen_blackboard(&self, key: &str)->Self{
        match self {
            Self::Value(value) 
                | Self::Constant(_, value)
                | Self::Custom(_, value)
                | Self::Blackboard(_, value)
                => Self::Blackboard(key.to_string(), value.clone()),
        }
    }

    pub fn gen_constant(&self, key:&str)->Self {
        match self {
            Self::Value(value) 
                | Self::Constant(_, value)
                | Self::Custom(_, value)
                | Self::Blackboard(_, value)
                => Self::Constant(key.to_string(), value.clone()),
        }
    }

    pub fn gen_custom(&self, key:&str)->Self {
        match self {
            Self::Value(value) 
                | Self::Constant(_, value)
                | Self::Custom(_, value)
                | Self::Blackboard(_, value)
                => Self::Custom(key.to_string(), value.clone()),
        }
    }

    pub fn gen_value(&self)->Self {
        match self {
            Self::Value(value) 
                | Self::Custom(_, value)
                | Self::Blackboard(_, value)
                | Self::Constant(_, value)=> Self::Value(value.clone()),
        }
    }

    pub fn value(&self)->&super::Value {
        match self {
                Self::Value(value) 
                | Self::Blackboard(_, value) 
                | Self::Constant(_, value)
                | Self::Custom(_, value) => value,
        } 
    }

    pub fn is_same_type(&self, other:&super::Value)->bool {
        match self {
            Self::Value(value) 
                | Self::Blackboard(_, value) 
                | Self::Constant(_, value)
                | Self::Custom(_, value) => value.is_same_type(other),
        }
    }
}

impl From<super::Value> for BlackboardValue {
    fn from(value: super::Value)->Self {
        BlackboardValue::Value(value)
    }
}

impl From<&super::Value> for BlackboardValue {
    fn from(value: &super::Value)->Self {
        BlackboardValue::Value(value.clone())
    }
}

impl From<(String, super::Value)> for BlackboardValue {
    fn from((key, value): (String, super::Value))->Self {
        BlackboardValue::Blackboard(key, value)
    }
}

impl From<(&str, super::Value)> for BlackboardValue {
    fn from((key, value): (&str, super::Value))->Self {
        BlackboardValue::Blackboard(key.to_string(), value)
    }
}
